<%@page import="com.qianduo.vo.CitiesForm,com.qianduo.util.Global,com.qianduo.vo.QianduoAgencyForm"%>
<%@page import="java.util.Map,java.util.List,java.util.Map.Entry,com.qianduo.util.Common,common.util.StringUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/pages/jsp/common/head.jsp"%>
<%
	Object qianduoAgencyFormObj = request.getAttribute("qianduoAgencyForm");
	QianduoAgencyForm form		= null;
	String tmpType				= "-1";
	String tmpCityID			= "-1";
	String tmpProvinceID		= "-1";
	if(null != qianduoAgencyFormObj){
		form			= (QianduoAgencyForm)qianduoAgencyFormObj;
		tmpType			= null != form.getType() ? form.getType().toString() : "-1";
		tmpCityID		= null != form.getCityID() ? form.getCityID().toString() : "-1";
		tmpProvinceID	= StringUtil.isEmptyRetString(StringUtil.isEmptyRetString(Common.getProvinceID(tmpCityID),form.getProvinceID()),"-1");
	}
	currentTab	= "listAgency";
%>
<script type="text/javascript" src="<%=host%>/scripts/js/extendArray.js" ></script>
<script type="text/javascript" src="<%=host%>/scripts/js/jquery/uploadfile/vendor/jquery.ui.widget.js" ></script>
<script type="text/javascript" src="<%=host%>/scripts/js/jquery/uploadfile/jquery.iframe-transport.js" ></script>
<script type="text/javascript" src="<%=host%>/scripts/js/jquery/uploadfile/jquery.fileupload.js" ></script>
<script type="text/javascript" src="<%=host%>/scripts/js/jquery/uploadfile/cors/jquery.xdr-transport.js" ></script>

<div class="wrapnme">
<!--citeLeft-->
    <%@ include file="/pages/jsp/common/left.jsp"%>
    <!--citeLeft结束-->    
    <!--sideRight-->
    <div class="sideRight">
		<!--title-->
        <div class="Right_title">
        	贷款信息添加
        </div>
        <!--title结束-->
        <!--content-->
        <div class="content">
        	<div style="color:red;">
        		<c:forEach var="error" items="${errors}" varStatus="count">
        			<div>${count.index + 1}.${error}</div>
        		</c:forEach>
        	</div>
        	<form action="<%=host%>/qianduoAgency.do?action=saveOrUpdateAgency" method="post">
        		<input type="hidden" name="id" id="id" value="${qianduoAgencyForm.id}" />        		
	        	 <table width="100%" border="1" class="tablesorter" cellpadding="0" cellspacing="0" >
	        	 	<tr>
	        	 		<th>用户名</th>
	        	 		<td>${_account.username}</td>
	        	 		<th></th>
	        	 		<td></td>
	        	 	</tr>
	        		<tr>
	        			<th>图片:</th>
		        	 	<td>
		        	 	<c:if test="${empty qianduoAgencyForm.image}">
		        	 		<img src="<%=host%>/images/logo.jpg" alt="logo" id="logo" />
		        	 	</c:if>
		        	 	<c:if test="${not empty qianduoAgencyForm.image}">
		        	 		<img src="${qianduoAgencyForm.image}" alt="logo" id="logo" />
		        	 	</c:if>
		        	 	<input type="file" id="fileupload" name="image" data-url="<%=host%>/uploadServlet" style="display:none;"/></td>
		        	 	<th>名称:</th>
		        	 	<td><input type="text" id="name" name="name" value="${qianduoAgencyForm.name}" /></td>
	        		</tr>
	        		<tr>		        	 	
		        	 	<th>分机号码:</th>
		        	 	<td><input type="text" id="ext" name="ext" value="${qianduoAgencyForm.ext}" /></td>
		        	 	<th>评级:</th>
		        	 	<td>
		        	 		<select name="recommendStar" id="recommendStar" >
			        	 		<option value="">请选择</option>
			        	 		<option value="5" ${qianduoAgencyForm.recommendStar == 5 ? "selected='selected'" : ""} >5星</option>
			        	 		<option value="4" ${qianduoAgencyForm.recommendStar == 4 ? "selected='selected'" : ""} >4星</option>
			        	 		<option value="3" ${qianduoAgencyForm.recommendStar == 3 ? "selected='selected'" : ""} >3星</option>
			        	 		<option value="2" ${qianduoAgencyForm.recommendStar == 2 ? "selected='selected'" : ""} >2星</option>
			        	 		<option value="1" ${qianduoAgencyForm.recommendStar == 1 ? "selected='selected'" : ""} >1星</option>	        	 		
		        	 		</select>
		        	 	</td>
	        	 	</tr>
	        	 	<tr>
		        	 	<th>联系电话:</th>
		        	 	<td>
		        	 		<input type="text" name="phone" id="phone" value="${qianduoAgencyForm.phone}" />
		        	 	</td>
		        	 	<th>城市:</th>
		        	 	<td>
		        	 		<select name="province" id="province"><option value="">请选择</option>
		        	 			<%
		        	 				Map<String,List<CitiesForm>> citiesMap	=	Global.citiesMap;
		        	 			for(Entry<String,List<CitiesForm>> entry : citiesMap.entrySet()){
		        	 				String province		= entry.getKey();
		        	 				String provinceID	= "";
		        	 				List<CitiesForm> citiesList	= entry.getValue();
		        	 				if(null != citiesList && citiesList.size() > 0){
		        	 					provinceID		= citiesList.get(0).getPid().toString();
		        	 				}
		        	 				out.print("<option value='"+provinceID+"' "+(tmpProvinceID.equals(provinceID) ? "selected='selected'" : "")+">"+province+"</option>");
		        	 			}
		        	 			%>
		        	 		</select>
		        	 		<select name="cityID" id="cityID">
		        	 			
		        	 		</select>
		        	 	</td>
	        	 	</tr>
	        	 	<tr>
	        	 		<th>公司名称</th>
		        	 	<td><input type="text" name="companyName" id="companyName" size="40" value="${qianduoAgencyForm.companyName}"/></td>	        	 		
		        	 	<th>简要说明:</th>
		        	 	<td><textarea name="summary" id="summary" rows="8" cols="40">${qianduoAgencyForm.summary}</textarea></td>
	        	 	</tr>
	        	 	<tr>
	        	 		<th>联系地址</th>
		        	 	<td><input type="text" name="address" id="address" size="40" value="${qianduoAgencyForm.address}"/></td>		        	 	
		        	 	<th>简介:</th>
		        	 	<td><textarea name="description" id="description" rows="8" cols="40">${qianduoAgencyForm.description}</textarea></td>	        	 		
		        	 </tr>
	        	 	<tr>
	        	 		<th>是否实名认证</th>
		        	 	<td><input type="checkbox" name="isCert" id="isCert" value="1" ${qianduoAgencyForm.isCert == 1 ? "checked='checked'" : ""}/></td>
	        	 		<th>业务范围:</th>
		        	 	<td>
		        	 		<%
								Map<String,String> productTypeMap	= Global.productTypeMap;
		        	 			for(Entry<String,String> entry : productTypeMap.entrySet()){
		        	 				String code		= entry.getKey();
		        	 				String name		= entry.getValue();
		        	 				out.print(name+"<input type='checkbox' name='productTypes' id='productTypes' value='"+code+"' />");
		        	 			}
		        	 		%>
		        	 	</td>
	        	 	</tr>	 	
	        	 	<tr id="businessLicense">
	        	 		<th>营业执照实名认证</th>
		        	 	<td><input type="checkbox" name="IsBusinessLicense" id="isBusinessLicense" value="1" ${qianduoAgencyForm.isBusinessLicense == 1 ? "checked='checked'" : ""}/></td>		        	 	
	        	 		<th></th>
		        	 	<td></td>
	        	 	<tr>	        	 		
		        	 	<td colspan="4" style="text-align:center;"><input type="submit" value="提交" accesskey="S"/></td>
	        	 	</tr>       	 	
	        	</table>
        	</form>
        <!-- content结束-->
 	</div>
    <!--sideRight结束-->
</div>
<!--wrap结束-->
<script>
	$(document).ready(function(){
		$('#logo').click(function(){
			$('#fileupload').click();
		});
		$('#fileupload').fileupload({
			done:function(e,obj){
		        //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
		        //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
		        //返回的数据在result.result中，假设我们服务器返回了一个json对象
		        var resUrl	= obj.result+'?'+ Math.random();
		        $('#logo').attr("src",resUrl);
		    }
		});
		
		$('#type').change(function(){
			var $val	= $(this).val();
			if($val == 2){
				$('#businessLicense').show();
			}else{
				$('#businessLicense').hide();
			}
		});
		$('#type').change();
		$('#province').change(function(){
			var $val		= $(this).val();
			var $htmlStr	= '';
			<%
	 			for(Entry<String,List<CitiesForm>> entry : citiesMap.entrySet()){
	 				String province		= entry.getKey();
	 				List<CitiesForm> citiesList	= entry.getValue();
	 				if(null != citiesList && citiesList.size() > 0){
	 					String provinceID	= citiesList.get(0).getPid().toString();
	 						%>if($val == '<%=provinceID%>'){<%
	 					for(CitiesForm city : citiesList){
	 						String cityName	= city.getCityName();
	 						String cityID	= city.getId().toString();
	 						%>$htmlStr+= "<option value='<%=cityID%>' <%=tmpCityID.equals(cityID) ? "selected='selected'" : ""%> ><%=cityName%></option>";<%
	 					}
	 					%>}<%
	 				}
	 			}
 			%>
 			$('#cityID').html($htmlStr);
		});
		
		$('#province').change();
	});
</script>
<%@ include file="/pages/jsp/common/footer.jsp"%>